home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / HISTORY.H < prev    next >
C/C++ Source or Header  |  1990-11-14  |  6KB  |  163 lines

  1. /* -*-C-*-
  2.  
  3. $Header: history.h,v 9.27 90/11/14 10:57:45 GMT cph Exp $
  4.  
  5. Copyright (c) 1987, 1988, 1989, 1990 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* History maintenance data structures and support. */
  36.  
  37. /* The history consists of a "vertebra" which is a doubly linked ring,
  38.    each entry pointing to a "rib".  The rib consists of a singly
  39.    linked ring whose entries contain expressions and environments. */
  40.  
  41. #define HIST_RIB        0
  42. #define HIST_NEXT_SUBPROBLEM    1
  43. #define HIST_PREV_SUBPROBLEM    2
  44. #define HIST_MARK        1
  45.  
  46. #define RIB_EXP            0
  47. #define RIB_ENV            1
  48. #define RIB_NEXT_REDUCTION    2
  49. #define RIB_MARK        2
  50.  
  51. #define HISTORY_MARK_TYPE (UNMARKED_HISTORY_TYPE ^ MARKED_HISTORY_TYPE)
  52. #define HISTORY_MARK_MASK (HISTORY_MARK_TYPE << DATUM_LENGTH)
  53.  
  54. #if ((UNMARKED_HISTORY_TYPE | HISTORY_MARK_TYPE) != MARKED_HISTORY_TYPE)
  55. #include "error: Bad history types in types.h and history.h"
  56. #endif
  57.  
  58. #define HISTORY_MARK(object) (object) |= HISTORY_MARK_MASK
  59. #define HISTORY_UNMARK(object) (object) &=~ HISTORY_MARK_MASK
  60. #define HISTORY_MARKED_P(object) (((object) & HISTORY_MARK_MASK) != 0)
  61.  
  62. /* Save_History places a restore history frame on the stack. Such a
  63.    frame consists of a normal continuation frame plus a pointer to the
  64.    stacklet on which the last restore history is located and the
  65.    offset within that stacklet.  If the last restore history is in
  66.    this stacklet then the history pointer is #F to signify this.  If
  67.    there is no previous restore history then the history pointer is #F
  68.    and the offset is 0. */
  69.  
  70. #define Save_History(Return_Code)                    \
  71. {                                    \
  72.   STACK_PUSH                                \
  73.     ((Prev_Restore_History_Stacklet == NULL)                \
  74.      ? SHARP_F                                \
  75.      : (MAKE_POINTER_OBJECT                        \
  76.     (TC_CONTROL_POINT, Prev_Restore_History_Stacklet)));        \
  77.   STACK_PUSH (LONG_TO_UNSIGNED_FIXNUM (Prev_Restore_History_Offset));    \
  78.   Store_Expression                            \
  79.     (MAKE_POINTER_OBJECT (UNMARKED_HISTORY_TYPE, History));        \
  80.   Store_Return (Return_Code);                        \
  81.   Save_Cont ();                                \
  82.   History = (OBJECT_ADDRESS (Get_Fixed_Obj_Slot (Dummy_History)));    \
  83. }
  84.  
  85. /* History manipulation in the interpreter. */
  86.  
  87. #ifndef DISABLE_HISTORY
  88.  
  89. #define New_Subproblem(expression, environment)                \
  90. {                                    \
  91.   History = (OBJECT_ADDRESS (History [HIST_NEXT_SUBPROBLEM]));        \
  92.   HISTORY_MARK (History [HIST_MARK]);                    \
  93.   {                                    \
  94.     fast SCHEME_OBJECT * Rib = (OBJECT_ADDRESS (History [HIST_RIB]));    \
  95.     HISTORY_MARK (Rib [RIB_MARK]);                    \
  96.     (Rib [RIB_ENV]) = (environment);                    \
  97.     (Rib [RIB_EXP]) = (expression);                    \
  98.   }                                    \
  99. }
  100.  
  101. #define Reuse_Subproblem(expression, environment)            \
  102. {                                    \
  103.   fast SCHEME_OBJECT * Rib = (OBJECT_ADDRESS (History [HIST_RIB]));    \
  104.   HISTORY_MARK (Rib [RIB_MARK]);                    \
  105.   (Rib [RIB_ENV]) = (environment);                    \
  106.   (Rib [RIB_EXP]) = (expression);                    \
  107. }
  108.  
  109. #define New_Reduction(expression, environment)                \
  110. {                                    \
  111.   fast SCHEME_OBJECT * Rib =                        \
  112.     (OBJECT_ADDRESS                            \
  113.      (FAST_MEMORY_REF ((History [HIST_RIB]), RIB_NEXT_REDUCTION)));    \
  114.   (History [HIST_RIB]) =                        \
  115.     (MAKE_POINTER_OBJECT (UNMARKED_HISTORY_TYPE, Rib));            \
  116.   (Rib [RIB_ENV]) = (environment);                    \
  117.   (Rib [RIB_EXP]) = (expression);                    \
  118.   HISTORY_UNMARK (Rib [RIB_MARK]);                    \
  119. }
  120.  
  121. #define End_Subproblem()                        \
  122. {                                    \
  123.   HISTORY_UNMARK (History [HIST_MARK]);                    \
  124.   History = (OBJECT_ADDRESS (History [HIST_PREV_SUBPROBLEM]));        \
  125. }
  126.  
  127. #else /* DISABLE_HISTORY */
  128.  
  129. #define New_Subproblem(Expr, Env) {}
  130. #define Reuse_Subproblem(Expr, Env) {}
  131. #define New_Reduction(Expr, Env) {}
  132. #define End_Subproblem() {}
  133.  
  134. #endif /* DISABLE_HISTORY */
  135.  
  136. /* History manipulation for the compiled code interface. */
  137.  
  138. #ifndef DISABLE_HISTORY
  139.  
  140. #define Compiler_New_Reduction()                    \
  141. {                                    \
  142.   New_Reduction                                \
  143.     (SHARP_F,                                \
  144.      (MAKE_OBJECT (TC_RETURN_CODE, RC_POP_FROM_COMPILED_CODE)));    \
  145. }
  146.  
  147. #define Compiler_New_Subproblem()                    \
  148. {                                    \
  149.   New_Subproblem                            \
  150.     (SHARP_F,                                \
  151.      (MAKE_OBJECT (TC_RETURN_CODE, RC_POP_FROM_COMPILED_CODE)));    \
  152. }
  153.  
  154. #define Compiler_End_Subproblem End_Subproblem
  155.  
  156. #else /* DISABLE_HISTORY */
  157.  
  158. #define Compiler_New_Reduction()
  159. #define Compiler_New_Subproblem()
  160. #define Compiler_End_Subproblem()
  161.  
  162. #endif /* DISABLE_HISTORY */
  163.